<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <div>
            <button @click="getCat">
                get a cat
            </button>
            <div v-if="!cats.length">
                没有多余的小猫了
            </div>
            <div 
                v-else
                v-for="(cat,idx) in cats"
                key="idx"
            >
                {{ cat.name }}
            </div>
        </div>
    </div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
<script>
    const baseUrl = 'http://localhost:3000'
    new Vue({
        el: '#app',
        data:{
            cats: []
        },
        mounted(){
        },
        methods:{
            async getCat(){
                try {
                    let res = await fetch(baseUrl + '/cats',{
                        method: 'POST',
                        headers:{
                            'Content-Type': 'application/json',
                        }
                    })
                    res = await res.json()
                    this.cats = res
                } catch (error) {
                    console.log(error);
                }
            }
        }
    })
</script>
</html>